package leetcode;

/**
 * 5. 最长回文子串
 */
public class Solution5 {
    public String longestPalindrome(String s) {
        String res = "";
        for (int i = 0; i < s.length(); i++) {
            String res1 = palindrome(s,i,i);
            String res2 = palindrome(s,i,i+1);
            res = res.length()> res1.length() ?res:res1;
            res = res.length()> res2.length() ?res:res2;
        }
        return res;
    }

    String palindrome(String s, int l, int r) {
        while(l>=0 && r <s.length() && s.charAt(l) == s.charAt(r)){
            l--;
            r++;
        }
        return s.substring(l + 1, r);
    }
}
